<fb:dashboard>
<fb:action href="invite.php">
Invite some friends over!
</fb:action>
<fb:action href="sendMessage.php">
Send a voice message to a friend!
</fb:action>
<fb:action href="getMessages.php">
Hear a voice message from your friends!
</fb:action>
<fb:help href="help.php">
Help Me!
</fb:help>
</fb:dashboard>
<?php

	require_once 'appinclude.php';
	require_once 'logsLib.php';
	require_once 'sqlLib.php';
	$currentPage = "record";
	
	// get the recipient (if there is one):
	if (isset($_GET['recipient'])) {
		$recipient = $_GET['recipient'];
	}
	$user_id = $facebook->user;
	logAfterRedirection($user_id,"sendMessage.php","record.php?recipient=$recipient");
	
	$sqlDb = new mysqli("localhost", "root", "", "messages");
	/* check connection */
	if (mysqli_connect_errno()) {
    	documentError($user_id,$currentPage,"Connect failed: ".mysqli_connect_error());
    	printErrorMsg("connecting to the database");
	} else {
		logMysqliConnectionOpened($user_id,$currentPage);
		// check how many messages user already recorded (and are saved):
		$recordedAmount = countMessages($sqlDb,$user_id,"recorded");
		logFunctionCall($user_id, countMessages, "sqlDb,".$user_id.",recorded", $recordedAmount,$currentPage);
		if ($recordedAmount>=10) {
			//user cannot record a new message:
			$sqlDb->close();
			logMysqliConnectionClosed($user_id,$currentPage);
			logRedirection($user_id, "error.php?action=record",$currentPage);
			echo "<fb:explanation>
				<fb:message>You can have only 10 recorded messages at all times.</fb:message>
				If you want to record a new message, you have to delete one of the old ones first.
				You can <a href=\"sendMessage.php\"> Review your existing recorded messages </a> or <a href=\"index.php\"> do anything else </a>
				</fb:explanation>";
		} else {
			//user can record a new message:
			$sqlDb->close();
			logMysqliConnectionClosed($user_id,$currentPage);
			$newFileName = $facebook->user.time().".au";
			echo" <table cellpadding=\"10\" align=\"center\" border=\"0\">
				<tr><td align=\"center\">
				<p align=\"center\">
				<h1 align=\"center\">&nbsp;</h1>
				<h1 align=\"center\"><font color=\"#0e1f5b\" size=\"5\">
				Choose a Name For Your Newly Born Message</font></h1>
				</p>
				<p align=\"center\">&nbsp;</p>
				<fb:user-agent includes=\"ie\" >
				<form method=\"POST\" action=\"$server\soundRecorder.php\">
				<p align=\"center\">
					<input type=\"text\" name=\"message_name\" value=\"Enter The Best Name You Can Think Of Here\" style=\"color: #000080; width: 262px\">
					</p>
					<input type=\"hidden\" name=\"newFileName\" value=\"$newFileName\" />
					<input type=\"hidden\" name=\"recipient\" value=\"$recipient\" />
					<p align=\"center\">
					<input type=\"submit\" value=\"Oh Yeah, I like That, Let's Record!\" name=\"B1\" style=\"color: #FFFFFF; width: 220px; background-color: #3b5998 \">
					</p>
				</form>
				<form method=\"POST\" action=\"sendMessage.php\">
					<p align=\"center\">
					<input type=\"submit\" value=\"Go Back!! I Didn't Mean It...\" name=\"B2\" style=\"color: #FFFFFF; width: 220px; background-color: #3b5998\">
					</p>
				</form>
				</fb:user-agent>
		
		
		
				<fb:user-agent includes=\"firefox\" >
				<form method=\"POST\" action=\"$server/soundRecorder.php\">
				<p align=\"center\">
					<input type=\"text\" name=\"message_name\" value=\"Enter The Best Name You Can Think Of Here\" style=\"color: #000080; width: 262px\">
					</p>
					<input type=\"hidden\" name=\"newFileName\" value=\"$newFileName\" />
					<input type=\"hidden\" name=\"recipient\" value=\"$recipient\" />
					<p align=\"center\">
					<input type=\"submit\" value=\"Oh Yeah, I like That, Let's Record!\" name=\"B1\" style=\"color: #FFFFFF; width: 220px; background-color: #3b5998 \">
					</p>
				</form>
				<form method=\"POST\" action=\"sendMessage.php\">
					<p align=\"center\">
					<input type=\"submit\" value=\"Go Back!! I Didn't Mean It...\" name=\"B2\" style=\"color: #FFFFFF; width: 220px; background-color: #3b5998\">
					</p>
				</form>
				</fb:user-agent>
		
				</td></tr></table>";
			
		}
	}
	

	
?>


</br>
<font size="3">
This application participates in Unicell's contest. <a href="http://www.liveface.co.il/%D7%AA%D7%97%D7%A8%D7%95%D7%AA-%D7%90%D7%A4%D7%9C%D7%99%D7%A7%D7%A6%D7%99%D7%95%D7%AA-%D7%A4%D7%99%D7%99%D7%A1%D7%91%D7%95%D7%A7/apps/" > For rating and other applications. </a>
</font>